//
//  ShooterViewController.m
//  BallRankingProject
//
//  Created by lanou3g on 15/6/2.
//  Copyright (c) 2015年 luojian. All rights reserved.
//

#import "ShooterViewController.h"
#import "UIImageView+WebCache.h"
@interface ShooterViewController ()

@end

@implementation ShooterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titleArray=[NSArray array];
   
    CGRect frame=CGRectMake(0, 0,CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)-64);
    self.view.frame=frame;
    //self.view.backgroundColor=[UIColor colorWithRed:0.970 green:0.092 blue:1.000 alpha:1.000];
    
   // [self reportMessage];
    [self.tableView reloadData];
    
}
//分析数据
- (void)reportMessage
{
    NSArray *array=[_dic objectForKey:@"ranks_data"];
    self.titleArray=array[0];
    if (_allArray==nil) {
         self.allArray=[NSMutableArray array];
    
    for (int i=1; i<array.count; i++) {
        NSArray *arr=array[i];
        [_allArray addObject:arr];
    }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    [self reportMessage];
     //NSLog(@"===%@",_dic);
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return _allArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CHLGshooterCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell" ];
    if (!cell) {
        cell=[[CHLGshooterCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"myCell"];
    }
    NSArray *arr=_allArray[indexPath.row];
    [self giveCellMessage:cell Array:arr];
    
    return cell;
}
//给cell赋值
- (void)giveCellMessage:(CHLGshooterCell *)cell Array:(NSArray *)array
{
    cell.numberLable.text=[NSString stringWithFormat:@"%@",array[0]];
    cell.nameLable.text=array[1];
    cell.teamLable.text=array[3];
    cell.ballcountLable.text=[NSString stringWithFormat:@"%@",array[4]];

    NSString *str=array[2];
    [cell.headiconImageview sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"placeHold"]];
  //  [cell.headiconImageview  sd_setImageWithURL:[NSURL URLWithString:str]];
}
- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;

}
- (CGFloat )tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}

//设置区头里面的view
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.frame), 40)];
    headView.backgroundColor=[UIColor colorWithRed:0.276 green:0.419 blue:0.569 alpha:1.000];
  //  headView.backgroundColor=[UIColor whiteColor];
    UILabel *numberLable=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(headView.frame)/6, CGRectGetHeight(headView.frame))];
    [headView addSubview:numberLable];
    numberLable.textAlignment=1;
    
    UILabel *nameLable=[[UILabel alloc] initWithFrame:CGRectMake(CGRectGetWidth(headView.frame)/6, 0, CGRectGetWidth(headView.frame)/6*2, CGRectGetHeight(headView.frame))];
    [headView addSubview:nameLable];
    nameLable.textAlignment=1;
    UILabel *teamNameLable=[[UILabel alloc] initWithFrame:CGRectMake(CGRectGetWidth(headView.frame)/6*3, 0, CGRectGetWidth(headView.frame)/6*2, CGRectGetHeight(headView.frame))];
    [headView addSubview:teamNameLable];
    teamNameLable.textAlignment=1;
    UILabel *numberOfBallLable=[[UILabel alloc] initWithFrame:CGRectMake(CGRectGetWidth(headView.frame)/6*5, 0, CGRectGetWidth(headView.frame)/6, CGRectGetHeight(headView.frame))];
    [headView addSubview:numberOfBallLable];
    numberOfBallLable.textAlignment=1;
    numberLable.text=_titleArray[0];
    nameLable.text=_titleArray[1];
    teamNameLable.text=_titleArray[3];
    numberOfBallLable.text=_titleArray[4];
    nameLable.font=[UIFont systemFontOfSize:11.0];
    numberOfBallLable.font=[UIFont systemFontOfSize:11.0];
    numberLable.font=[UIFont systemFontOfSize:11.0];
    teamNameLable.font=[UIFont systemFontOfSize:11.0];
//    numberLable.backgroundColor=[UIColor redColor];
//    nameLable.backgroundColor=[UIColor blueColor];
//    teamNameLable.backgroundColor=[UIColor yellowColor];
//    numberOfBallLable.backgroundColor=[UIColor redColor];
    
    
    
    return headView;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *arr=_allArray[indexPath.row];
    NSString *string=arr[5];
    
    BingTouchController *detailsVC=[[BingTouchController alloc] init];
    detailsVC.str=string;
    detailsVC.title=arr[1];
    
//    CATransition *transition=[CATransition animation];
//    transition.duration=5.0f;
//    transition.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
//    transition.type=kCATransitionPush;
//    transition.subtype=kCATransitionFromRight;
//    transition.delegate=self;
  //  transition.fillMode=kCAFillModeRemoved;
    //transition.speed=1.0f;
//    [detailsVC.view.layer addAnimation:transition forKey:nil];
    
    
    
    
    [self.navigationController pushViewController:detailsVC animated:YES];
    
    
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
